import re

def readfile(name): file = open(name, 'r')

ARs = []
CRs = []

current = 1

# Read list of lines
out = []  # list to save lines
while True:
    # Read next line
    line = file.readline()
    # If line is blank, then you struck the EOF
    if not line:
        break

    if "AR" in line and "CR" in line:

        ar_value = ""
        cr_value = ""
        splited = line.split(" ")
        # put the CR, AR to the dict
        for x in splited:
            splited2 = re.split(':|,', x)
            if splited2.__len__() > 1 and (splited2[0] == "AR" or splited2[0] == "CR"):
                if splited2[0] == "AR":
                    ar_value = splited2[1]
                    ARs.append(ar_value)
                if splited2[0] == "CR":
                    cr_value = splited2[1]
                    CRs.append(cr_value)

        out.append({"index": current, "AR": ar_value, "CR": cr_value})
        current = current + 1

# Close file
file.close()

print("ARsの一番いいモデルは：")
ARs.sort()
out_ARs = sorted(out, key = lambda i: i['AR'])
print(out_ARs[len(out_ARs)-1])


print("-------------------------------------------\r\n")

print("CRsの一番いいモデルは")
CRs.sort()
out_CRs = sorted(out, key = lambda i: i['CR'])
print(out_CRs[len(out_CRs)-1])
if name == 'main': readfile("C:/Users/li.yang.pfu/Desktop/sample/valid.csv")